import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 审核项信息 */
export interface AuditConfig {
  id: number // id
  auditTypeId?: number // 分类
  name?: string // 分类名称
  description: string // 描述
}

/** 审核类型配置信息 */
export interface AuditType {
  id: number // id
  name?: string // 分类名称
  status: number // 状态
  description: string // 描述
  auditconfigs?: AuditConfig[]
}

// 审核类型配置 API
export const AuditTypeApi = {
  // 查询审核类型配置分页
  getAuditTypePage: async (params: any) => {
    return await request.get({ url: `/business/audit-type/page`, params })
  },

  // 查询所有审核类型
  getAuditTypeList: async () => {
    return await request.get({ url: `/business/audit-type/list` })
  },

  // 查询审核类型配置详情
  getAuditType: async (id: number) => {
    return await request.get({ url: `/business/audit-type/get?id=` + id })
  },

  // 新增审核类型配置
  createAuditType: async (data: AuditType) => {
    return await request.post({ url: `/business/audit-type/create`, data })
  },

  // 修改审核类型配置
  updateAuditType: async (data: AuditType) => {
    return await request.put({ url: `/business/audit-type/update`, data })
  },

  // 删除审核类型配置
  deleteAuditType: async (id: number) => {
    return await request.delete({ url: `/business/audit-type/delete?id=` + id })
  },

  /** 批量删除审核类型配置 */
  deleteAuditTypeList: async (ids: number[]) => {
    return await request.delete({ url: `/business/audit-type/delete-list?ids=${ids.join(',')}` })
  },

  // 导出审核类型配置 Excel
  exportAuditType: async (params) => {
    return await request.download({ url: `/business/audit-type/export-excel`, params })
  },

  // ==================== 子表（审核项） ====================

  // 获得审核项列表
  getAuditConfigListByAuditTypeId: async (auditTypeId) => {
    return await request.get({
      url: `/business/audit-type/audit-config/list-by-audit-type-id?auditTypeId=` + auditTypeId
    })
  },

  // 获得待审核项列表
  getAuditConfigListByAuditTypeIdWait: async (auditTypeId, levelId) => {
    return await request.get({
      url: `/business/audit-type/audit-config/list-by-audit-type-id-wit?auditTypeId=${auditTypeId}&levelId=${levelId}`
    })
  }
}
